package com.itheima.controller;

import com.itheima.entity.TbUser;
import com.itheima.service.TbUserService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 用户信息表(TbUser)表控制层
 *
 * @author makejava
 * @since 2020-07-17 20:51:35
 */
@RestController
@RequestMapping("tbUser")
@RefreshScope
public class TbUserController {
    /**
     * 服务对象
     */
    @Resource
    private TbUserService tbUserService;

    @Value("${server.port}")
    private String port;

    @Value("${personName}")
    private String personName;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne/{id}")
    public TbUser selectOne(@PathVariable("id") Integer id) {
        TbUser user = tbUserService.queryById(id);
        user.setNote("生产者端口号是: " + port);
        return user;
    }

    @GetMapping("/getPersonName")
    public String getPersonName(){
        return personName;
    }

}